package edu.sdjzu.exam.service.rbac;

import edu.sdjzu.exam.common.CommonResponse;
import edu.sdjzu.exam.domain.auth.Permission;
import edu.sdjzu.exam.domain.auth.Role;
import edu.sdjzu.exam.domain.auth.User;

import java.util.List;

public interface RbacService {
    // 用户操作
    List<User> getAllUsers();
    User createUser(User user);
    User findUserById(Long userId);
    User findUserByUsername(String username);
    User findUserByEmail(String email);
    void updateUser(User user);
    void deleteUser(Long userId);
    
    // 超级管理员创建老师用户
    CommonResponse<String> createTeacherUser(String username, String password, String email, String realname, Long adminId);

    // 角色操作
    List<Role> getAllRoles();
    Role createRole(Role role);
    Role findRoleById(Long roleId);
    Role findRoleByName(String roleName);
    void updateRole(Role role);
    void deleteRole(Long roleId);

    // 权限操作
    List<Permission> getAllPermissions();
    Permission createPermission(Permission permission);
    Permission findPermissionById(Long permissionId);
    Permission findPermissionByName(String permissionName);
    void updatePermission(Permission permission);
    void deletePermission(Long permissionId);

    // 用户-角色分配
    void assignRoleToUser(Long userId, Long roleId);
    void removeRoleFromUser(Long userId, Long roleId);
    List<Role> getUserRoles(Long userId);
    List<Role> findRolesByUserId(Long userId);


    // 角色-权限分配
    void assignPermissionToRole(Long roleId, Long permissionId);
    void removePermissionFromRole(Long roleId, Long permissionId);
    List<Permission> getRolePermissions(Long roleId);

    // 权限检查
    boolean hasPermission(Long userId, String permissionName);
    
    // 通过角色查询用户
    List<User> findUsersByRole(String roleName);
    List<User> findUsersByRoleId(Long roleId);
}